Skip to content

[9.4] [Canvas] Fix stale nextPage closure in autoplay timer (fix #268125) (#268398)#271819

Merged
kibanamachine merged 2 commits into
elastic:9.4from
kibanamachine:backport/9.4/pr-268398
Jun 1, 2026
Merged

[9.4] [Canvas] Fix stale nextPage closure in autoplay timer (fix #268125) (#268398)#271819
kibanamachine merged 2 commits into
elastic:9.4from
kibanamachine:backport/9.4/pr-268398

Conversation

@kibanamachine
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.4:

Questions ?

Please refer to the Backport tool documentation

…8125) (elastic#268398)

## Summary
Fixes elastic#268125

useEffect cleanup runs after browser paint, creating a window where a
pending setTimeout can fire with a stale nextPage closure after pages
are added or removed. Fix by storing nextPage in a ref that is updated
synchronously during the render phase, so the callback always calls the
current function regardless of effect timing.

Also adds unit tests that document the exact race-window behaviour.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit e740fb6)
@kibanamachine kibanamachine added the backport This PR is a backport of another PR label May 29, 2026
@kibanamachine kibanamachine enabled auto-merge (squash) May 29, 2026 02:09
@adrianchen-es
Copy link
Copy Markdown
Contributor

/ci

@adrianchen-es
Copy link
Copy Markdown
Contributor

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor Author

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #92 / Cloud Security Posture - Group 5 (KSPM + Flyouts) Security Alerts Page - Graph visualization expanded flyout - filter by node

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
canvas 1.1MB 1.1MB +52.0B

History

cc @adrianchen-es

@kibanamachine kibanamachine merged commit 5bad6ea into elastic:9.4 Jun 1, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants